home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / networking / HIPPI / blast.c next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.9 KB  |  155 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  * blast.c
  19.  *
  20.  * blast [-1] [-H] [-I<ifield>] [-D<device-file>] [size [pkts-per-pass [passes] ] ]
  21.  *
  22.  * Test HIPPI-FP interface output performance.
  23.  *
  24.  */
  25. #include <stdio.h>
  26. #include <fcntl.h>
  27. #include <stdlib.h>
  28. #include <sys/types.h>
  29. #include <sys/wait.h>
  30. #include <sys/times.h>
  31.  
  32. #include <sys/hippi.h>
  33.  
  34. #include <sys/errno.h>
  35. extern int errno;
  36.  
  37. static char *src_err_name[] =
  38.     { "no error", "HIPPI sequence error", "HIPPI source lost DSIC",
  39.       "HIPPI source timeout", "HIPPI source lost connect",
  40.       "HIPPI connect rejection", "HIPPI interface shutdown" };
  41.  
  42. #define DEVICE_FILE    "/dev/hippi0"
  43.  
  44. main(int argc, char *argv[] )
  45. {
  46.     register int i, j;
  47.     int    fd, status;
  48.     int    len=0x200000, retv;
  49.     int    n = 500, m = 1, child, nofork=0, sendH=0, arg;
  50.     u_long    *buf;
  51.     hippi_fp_t    fphead;
  52.     u_long    d1head[6];
  53.     u_long    I = 0x00000008;
  54.     struct tms tm_dummy;
  55.     clock_t    start_time, end_time;
  56.     float    mbytes, t;
  57.     char    *device_name = DEVICE_FILE;
  58.  
  59.     arg = 1;
  60.     if ( argc>arg && argv[arg][0] == '-' && argv[arg][1] == '1' )
  61.         nofork++,arg++;
  62.     if ( argc>arg && argv[arg][0] == '-' && argv[arg][1] == 'H' )
  63.         sendH++,arg++;
  64.     if ( argc>arg && argv[arg][0] == '-' && argv[arg][1] == 'I' )
  65.         I = strtoul( argv[arg++]+2, NULL, 16 );
  66.     if ( argc>arg && argv[arg][0] == '-' && argv[arg][1] == 'D' )
  67.         device_name = argv[arg++]+2;
  68.     if ( argc>arg )
  69.         len = atoi( argv[arg++] );
  70.     if ( argc>arg )
  71.         n = atoi( argv[arg++] );
  72.     if ( argc>arg )
  73.         m = atoi( argv[arg++] );
  74.     
  75.     if ( (len & 7) || len < 32 || n < 2 || m < 1 )
  76.         fprintf( stderr,"blast: parameter error\n" ),exit(1);
  77.     
  78.     buf = memalign( 8, len );
  79.     mpin( buf, len );
  80.  
  81.     printf("blast(%s): sending %d packets of length %d to I=0x%08X \
  82. (%d meg total)\n", device_name, n * m, len, I, n*m*len/0x100000 );
  83.  
  84.     srand48( time(0) );
  85.  
  86.     for ( i=0; i<(len+3)/4; i++ )
  87.         if ( sendH )
  88.             buf[ i ] = 0x48484848;    /* HHHH */
  89.         else
  90.             buf [ i ] = mrand48();
  91.  
  92. /* alternating 00000000 and FFFFFFFF .....
  93.             buf[ i ] = (i&1) ? 0xFFFFFFFF : 0x00000000;
  94.  */
  95.     
  96.     fd = open( device_name, O_WRONLY );
  97.     if ( fd < 0 )
  98.         perror( "blast: couldn't open hippi device" ),exit(1);
  99.     
  100.     /* Set ULP */
  101.     if ( ioctl( fd, HIPIOC_BIND_ULP, 0x17 ) < 0 )
  102.         perror( "blast: couldn't bind to ULP" ),exit(1);
  103.     
  104.     /* Set I-field */
  105.     if ( ioctl( fd, HIPIOCW_I, I ) < 0 )
  106.         perror( "blast: couldn't set I-field" );
  107.  
  108.     for (i=0; i<m; i++) {
  109.  
  110.         if ( ! nofork )
  111.             child = ( fork() == 0 );
  112.         else
  113.             child = 0;
  114.  
  115.         /* START */
  116.         start_time = times( &tm_dummy );
  117.  
  118.         for (j= ( nofork ? n : n/2 ); j > 0; j--) {
  119.             retv = write( fd, buf, len );
  120.             if ( retv != len ) {
  121.                 printf(
  122.                 "blast: (%s.%s) %d: write return value: %d\n",
  123.                     device_name,
  124.                     child ? "child" : "parent",
  125.                     i, retv );
  126.                 perror( "blast: trouble writing" );
  127.                 if ( retv < 0 && errno == EIO ) {
  128.                     retv = ioctl( fd, HIPIOCW_ERR );
  129.                     printf( "HIPPI error no %d %s\n",
  130.                     retv, (retv>0) ? src_err_name[retv] :
  131.                         "huh?" );
  132.                 }
  133.                 /* exit(1); */
  134.             }
  135.         }
  136.  
  137.         if ( child )
  138.             exit(0);
  139.         else
  140.             wait( &status );
  141.         
  142.         /* END */
  143.         end_time = times( &tm_dummy );
  144.  
  145.         t = (float)(end_time - start_time)/CLK_TCK;
  146.         mbytes = (float)n * len / 0x100000;
  147.         printf( "blast(%s): %f megabytes sent in %f s  (%f MB/s)\n",
  148.             device_name, mbytes, t, mbytes/t );
  149.  
  150.     }
  151.  
  152.     close(fd);
  153. }
  154.  
  155.